const { query } = require('./src/config/database');

async function debugIngredients() {
  try {
    console.log('=== 查询菜单项的ingredients字段原始数据 ===');
    const rows = await query('SELECT id, name, ingredients FROM menu_items LIMIT 5');
    
    rows.forEach((row, index) => {
      console.log(`\n--- 菜单项 ${index + 1} ---`);
      console.log('ID:', row.id);
      console.log('名称:', row.name);
      console.log('Ingredients原始值:', row.ingredients);
      console.log('Ingredients类型:', typeof row.ingredients);
      console.log('Ingredients长度:', row.ingredients ? row.ingredients.length : 'null');
      
      if (row.ingredients) {
        console.log('前50个字符:', row.ingredients.substring(0, 50));
        try {
          const parsed = JSON.parse(row.ingredients);
          console.log('JSON解析成功:', parsed);
        } catch (e) {
          console.log('JSON解析失败:', e.message);
        }
      }
    });
    
    process.exit(0);
  } catch (error) {
    console.error('查询失败:', error);
    process.exit(1);
  }
}

debugIngredients();